package com.peko.controller;

import com.peko.entity.Product;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * @Author：Peko
 * @Description：TODO
 * @Date：Created in 16:41 2023/7/31
 */

@RestController
@RequestMapping("product")
public class ProductController {

    private static final Logger log = LoggerFactory.getLogger(ProductController.class);

    @GetMapping("product")
    public String product(){
        log.info("进入商品服务");
        return "product ok";
    }

    //url拼接参数类型接口
    @GetMapping("/test")
    public String test(String name,Integer age){
        log.info("name = {}         age = {}",name,age);
        return "product test ok!";
    }

    //路径传递参数类型接口
    @GetMapping("/test1/{name}/{age}")
    public String test1(@PathVariable("name") String name, @PathVariable("age") Integer age){
        log.info("name = {}         age = {}",name,age);
        return "product test1 ok!";
    }

    //接收对象类型接口
    @PostMapping("test2")
    public String test2(@RequestBody Product product){
        log.info("接收参数：name = {}  age = {}",product.getName(),product.getAge());
        return "product test2 ok!";
    }

    //接收form表单类型接口
    @GetMapping("test3")
    public String test3(@RequestPart("product") Product product){
        log.info("接收参数：name = {}  age = {}",product.getName(),product.getAge());
        return "product test2 ok!";
    }
}
